﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Draco.OWF.RT;
using System.Collections;
using Draco.OWF.Exceptions;
using Draco.OWF.DataBinding;

namespace Draco.OWF.Acticity
{
    public abstract class AbstractActivity:IActivity
    {
        protected String m_Id = Guid.NewGuid().ToString();
        protected String m_Name = "No_Name";
        protected String m_DisplayName = "";
        protected IBindingDataItemCollection m_Input = new BindingDataItemCollection();
        protected IBindingDataItemCollection m_Output = new BindingDataItemCollection();
        protected Stack<ActivityRuntimeException> m_Exceptions = new Stack<ActivityRuntimeException>();

        private IActivityRender m_Render;
        
        /// <summary>
        /// Id
        /// </summary>
        public virtual string Id
        {
            get{return m_Id;}
            set{
                if (!String.IsNullOrEmpty(value))
                    m_Id = value;
            }
        }
        /// <summary>
        /// Name
        /// </summary>
        public virtual String Name { get { return m_Name; } set { m_Name = value; } }
        /// <summary>
        /// DisplayName
        /// </summary>
        public virtual String DisplayName
        {
            get { return String.IsNullOrEmpty(m_DisplayName) ? Name : m_DisplayName; }
            set { m_DisplayName = value; }
        }
        /// <summary>
        /// Description
        /// </summary>
        public virtual String Description { get; set; }
        /// <summary>
        /// RuntimeExceptions
        /// </summary>
        public Stack<ActivityRuntimeException> Exceptions
        {
            get { return m_Exceptions; }
        }

        public virtual IBindingDataItemCollection InputParameters
        {
            get { return m_Input; }
        }

        public virtual IBindingDataItemCollection OutputParameters
        {
            get { return m_Output; }
        }

        /// <summary>
        /// Get Render
        /// </summary>
        public virtual IActivityRender Render 
        {
            get
            {
                if (m_Render == null)
                {
                    m_Render = CreateRender();
                }
                return m_Render;
            }
        }

        #region protected
        protected virtual IActivityRender CreateRender()
        {
            return new DefaultActivityRender();
        }
        #endregion

        #region abstract method
        public abstract ITask CreateActivityInstance();
        public abstract string ActivityType { get; }
        public abstract void SerializeConfiguration(System.Xml.XmlElement parent);

        public abstract void DeserializeConfiguration(System.Xml.XmlElement parent);
        #endregion
    }
}
